package com.sx.gongzhong.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.model.ConvenniceAppealBean;
import com.sx.gongzhong.net.ServiceFactory;
import com.sx.gongzhong.utils.BaseUtil;

import java.util.List;

/**便民诉求
 * Created by admin on 2018/1/3.
 */

public class ConvenniceAppealAdapter  extends BaseQuickAdapter<ConvenniceAppealBean,BaseViewHolder> {

    private Context context;

    public ConvenniceAppealAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<ConvenniceAppealBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final ConvenniceAppealBean item) {

        helper.setText(R.id.tv_appealNum,"编号："+ item.appealNum);

        TextView tv_statu = helper.getView(R.id.tv_handleStatus);
        if (item.handleStatus.equals("to_be_accepted")){
            tv_statu.setText("待受理");
            tv_statu.setBackgroundResource(R.drawable.shape_red_corner_50);
        }else if (item.handleStatus.equals("accepted")){
            tv_statu.setText("已受理");
            tv_statu.setBackgroundResource(R.drawable.shape_green_corner_50);
        }else if (item.handleStatus.equals("already_done")){
            tv_statu.setText("已办结");
            tv_statu.setBackgroundResource(R.drawable.shape_orige_corner_50);
        }
        if (!BaseUtil.isEmpty(item.evaluationContent)){
            tv_statu.setText("已评价");
            tv_statu.setBackgroundResource(R.drawable.shape_orige_corner_50);
        }
        helper.setText(R.id.tv_content,item.content);

        ImageView imageView = helper.getView(R.id.iv_img);
        imageView.setVisibility(View.GONE);
        if (item.files != null && item.files.size() > 0){
            if (item.files.get(0).getFileType().equals("video")){
                imageView.setVisibility(View.VISIBLE);
                Glide.with(context).load(R.mipmap.img_video).into(imageView);
            }else if (item.files.get(0).getFileType().equals("audio")){
                imageView.setVisibility(View.VISIBLE);
                Glide.with(context).load(R.mipmap.img_audio).into(imageView);
            }else if (item.files.get(0).getFileType().equals("image")){
                imageView.setVisibility(View.VISIBLE);
                if (!BaseUtil.isEmpty(item.files.get(0).getPath())){
                    Glide.with(context).load(ServiceFactory.getUrl(item.files.get(0).getPath())).into(imageView);
                }
            }
        }

        helper.setText(R.id.tv_time,item.appealTime);
        helper.setText(R.id.tv_readTimes,item.readTimes);

        if (item.appeal != null){
            helper.setText(R.id.tv_name,item.appeal.getName());
            ImageView iv_headerUrl = helper.getView(R.id.iv_headerUrl);
            RequestOptions options = new RequestOptions().centerCrop()
                    .placeholder(R.mipmap.img_head_default)
                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                    .circleCrop()
                    .error(R.mipmap.img_head_default);
            Glide.with(context)
                    .load(ServiceFactory.getUrl( item.appeal.getHeaderUrl()) )
                    .apply(options)
                    .into(iv_headerUrl);
        }
    }
}
